package com.hschinese.pronunciation.activity;

import android.database.Cursor;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ListView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.adapter.StudayRecogintionListAdapter;
import com.hschinese.pronunciation.bean.AppDataBean;
import com.hschinese.pronunciation.bean.ListViewItem;
import com.hschinese.pronunciation.db.DBHelper;
import com.hschinese.pronunciation.utils.Logger;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class StudayRecognitionActivity extends BaseActivity {
    private static int lessonType = 14;
    @Bind(R.id.center_img_china)
    ImageView centerImgChina;
    @Bind(R.id.lv_recogniton_studay)
    ListView lvRecognitonStuday;
    private List mDataList;
    private Cursor cursor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_studay_recognition);
        ButterKnife.bind(this);
        innitView();
        List<ListViewItem> listViewItems = initVowelData();
        StudayRecogintionListAdapter studayRecogintionListAdapter = new StudayRecogintionListAdapter(listViewItems, this);
        lvRecognitonStuday.setAdapter(studayRecogintionListAdapter);
    }
    private List<ListViewItem> initVowelData() {
        List<ListViewItem> items = new ArrayList<ListViewItem>();
        ListViewItem singleVowelItem = new ListViewItem();
        ListViewItem doubleVowelItem = new ListViewItem();
        ListViewItem threeTimesVowelItem = new ListViewItem();
        mDataList = new ArrayList<AppDataBean>();
        cursor = DBHelper.getInstance(this).query(DBHelper.RES_TABLE, " type=? ", new String[]{lessonType + ""});
        if (cursor != null)
            Logger.e("xionghy-cursor: " + cursor.getCount());
        while(cursor.moveToNext()) {
            AppDataBean d = new AppDataBean();
            d.setChinese(cursor.getString(cursor.getColumnIndex("chinese")));
            d.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin")));
            d.setPhone(cursor.getString(cursor.getColumnIndex("phone")));
            d.setTone(cursor.getString(cursor.getColumnIndex("tone")));
            d.setAudioName(cursor.getString(cursor.getColumnIndex("audioName")));
            d.setPicName(cursor.getString(cursor.getColumnIndex("picName")));
            d.setType(cursor.getInt(cursor.getColumnIndex("type")));
            d.setGroupID(cursor.getInt(cursor.getColumnIndex("groupId")));
            d.setWeight(cursor.getInt(cursor.getColumnIndex("weight")));
            if (d.getGroupID() == 1) {
                singleVowelItem.mWords.add(d);
            } else if (d.getGroupID() == 2) {
                doubleVowelItem.mWords.add(d);
            } else if (d.getGroupID() == 3) {
                threeTimesVowelItem.mWords.add(d);
            }
        }
        items.add(singleVowelItem);
        items.add(doubleVowelItem);
        items.add(threeTimesVowelItem);
        cursor.close();
        return items;
    }
    private void innitView() {
        centerImgChina.setImageResource(R.mipmap.title_rendu);
    }

    @OnClick(R.id.left_img)
    public void onViewClicked() {
        this.finish();
    }
}
